package org.sdnstproject.interlayer.interlayerProxy;

import org.projectfloodlight.openflow.protocol.OFMessage;
import org.projectfloodlight.openflow.protocol.OFType;
import org.projectfloodlight.openflow.protocol.OFVersion;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

public class Metadata {

	private byte[] header;
    private byte[] data;
    private OFVersion version;
    private OFType type;
    private short length;
    private long xid;
    private OFMessage messageObject;
    
    public Metadata(byte[] header, byte[] msg) {
        this.header = header;
        this.data = msg;
    }

//    public void parseMessge() {
//        byte[] msg = getAllMsg();
//        ByteBuf buf= Unpooled.copiedBuffer(msg);
//        int offset = buf.readerIndex();
//        try {
//            this.messageObject = OFMessageParse(buf);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        this.version = this.messageObject.getVersion();
//        this.type = this.messageObject.getType();
//
//    }

    public byte[] getAllMsg() {
        int total = header.length + data.length;
        //System.out.println("total:" + total);
        byte[] msgData = new byte[total];
        int i = 0;
        // 这里可以使用两个system.arraycpoy 来写但是有空指针错误不能理解
        for (; i < header.length; i++) {
            msgData[i] = header[i];
        }
        for (; i < total; i++) {
            msgData[i] = data[i - header.length];
        }
        return msgData;
    }

    public OFVersion getVersion() {
        return version;
    }

    public OFType getType() {
        return type;
    }


    public OFMessage getContent() {
        return messageObject;
    }

    public void setVersion(OFVersion version) {
        this.version = version;
    }

    public void setType(OFType type) {
        this.type = type;
    }
}
